package com.bwhx.eruler.service.impl;

import java.util.HashMap;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.bwhx.eruler.bean.Buyer;
import com.bwhx.eruler.bean.ChangeVersion;
import com.bwhx.eruler.bean.Page;
import com.bwhx.eruler.bean.Ruler;
import com.bwhx.eruler.bean.Staff;
import com.bwhx.eruler.dao.BuyerDao;
import com.bwhx.eruler.dao.ChangeVersionDao;
import com.bwhx.eruler.dao.StaffDao;
import com.bwhx.eruler.service.ChangeVersionService;

/**
 * @Description:
 */
@Service
public class ChangeVersionServiceImpl implements ChangeVersionService {
	@Autowired 
	ChangeVersionDao cvDao;
	@Autowired
	BuyerDao buyerDao;
	
	@Autowired
	StaffDao staffDao;
	
	@Override
	public void insert(ChangeVersion cv, List<Ruler> rulers, HashMap<String,Integer> paramMap) {

		if(cv.getcVType()==1){
			Buyer buyer = buyerDao.findById(cv.getcVBuyerId());
			cv.setcVBuyerName(buyer.getbName());
		}else if(cv.getcVType()==0){
			Staff buyer = staffDao.findById(cv.getcVBuyerId());
			cv.setcVBuyerName(buyer.getsName());
		}
		
		
		Staff storekeeper = staffDao.findById(cv.getcVStorekeeperId());
		Staff proposer = staffDao.findById(cv.getcVProposerId());
		cv.setcVProposerName(proposer.getsName());
		cv.setcVStorekeeperName(storekeeper.getsName());
		
		cvDao.insert(cv,rulers);
		if(paramMap.size()!=0){
			buyerDao.update(paramMap);
		}
		
		
	}

	@Override
	public List<ChangeVersion> list(Page p) {
		return cvDao.list(p);
	}

	@Override
	public Integer count(ChangeVersion cv) {
		return cvDao.count(cv);
	}
	
	

}
